package com.sopaths.contracts.pagination;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class PagingList<E> implements List<E> {
	private List<E> innerList;

	private int currentPage;

	private int totalCount;

	private int pageSize;

	public PagingList(List<E> list) {
		this(list, 1, list.size(), Integer.MAX_VALUE - list.size());
	}

	public PagingList(List<E> list, int currentPage, int totalCount, int pageSize) {
		innerList = list;
		this.currentPage = currentPage;
		this.totalCount = totalCount;
		this.pageSize = pageSize;
	}

	public int getTotalPage() {
		int totalPage = (totalCount + pageSize - 1) / pageSize;
		return totalPage;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	/*Decorated method in List*/
	@Override
	public int size() {
		return innerList.size();
	}

	@Override
	public boolean isEmpty() {
		return innerList.isEmpty();
	}

	@Override
	public boolean contains(Object o) {
		return innerList.contains(o);
	}

	@Override
	public Iterator<E> iterator() {
		return innerList.iterator();
	}

	@Override
	public Object[] toArray() {
		return innerList.toArray();
	}

	@Override
	public <T> T[] toArray(T[] a) {
		return innerList.toArray(a);
	}

	@Override
	public boolean add(E e) {
		return innerList.add(e);
	}

	@Override
	public boolean remove(Object o) {
		return innerList.remove(o);
	}

	@Override
	public boolean containsAll(Collection<?> c) {
		return innerList.containsAll(c);
	}

	@Override
	public boolean addAll(Collection<? extends E> c) {
		return innerList.addAll(c);
	}

	@Override
	public boolean addAll(int index, Collection<? extends E> c) {
		return innerList.addAll(c);
	}

	@Override
	public boolean removeAll(Collection<?> c) {
		return innerList.removeAll(c);
	}

	@Override
	public boolean retainAll(Collection<?> c) {
		return innerList.retainAll(c);
	}

	@Override
	public void clear() {
		innerList.clear();
	}

	@Override
	public E get(int index) {
		return innerList.get(index);
	}

	@Override
	public E set(int index, E element) {
		return innerList.set(index, element);
	}

	@Override
	public void add(int index, E element) {
		innerList.add(index, element);
	}

	@Override
	public E remove(int index) {
		return innerList.remove(index);
	}

	@Override
	public int indexOf(Object o) {
		return innerList.indexOf(o);
	}

	@Override
	public int lastIndexOf(Object o) {
		return innerList.lastIndexOf(o);
	}

	@Override
	public ListIterator<E> listIterator() {
		return innerList.listIterator();
	}

	@Override
	public ListIterator<E> listIterator(int index) {
		return innerList.listIterator(index);
	}

	@Override
	public List<E> subList(int fromIndex, int toIndex) {
		return innerList.subList(fromIndex, toIndex);
	}
	/*End decorated method in List*/
}
